package com.gem.growingtree.service;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.util.Log;

import com.gem.growingtree.utils.HttpUtil;
import com.gem.growingtree.utils.StreamTool;

public class UserService {
	public static String checkUser(String uname, String upass) throws Exception {
		HttpClient client = new DefaultHttpClient();
		String path = HttpUtil.urlPath+"ws/login/main";
		HttpPost httpPost = new HttpPost(path);
		List<NameValuePair> parameters = new ArrayList<NameValuePair>();
		parameters.add(new BasicNameValuePair("userName", uname));
		parameters.add(new BasicNameValuePair("password", upass));
		httpPost.setEntity(new UrlEncodedFormEntity(parameters, "utf-8"));
		Log.i("AA", "AA52222222222222A");
		
		HttpResponse response = client.execute(httpPost);
		Log.i("AA", "AA55655AAA");
		int responseCode = response.getStatusLine().getStatusCode();
		if (responseCode == 200) {
			InputStream is = response.getEntity().getContent();
			String result = new String(StreamTool.readInputStream(is), "utf-8");
			Log.i("AA", "AAAccccccAA"+result);
			return result;
		} else {
			Log.i("AA", "AA1211111111111111111");
			Log.i("AA", responseCode+"");
			
			return "登录失败";
		}
	}
}
